package com.jinyu.gateway.registry;

import io.netty.channel.Channel;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Objects;


/**
 * 服务节点信息：
 * ip:port以及对应name，每个注册的server都必须要定义一个名字
 */
@Data
public class ServerNode {
    private String ip;
    private int port;
    private String name;

    private final Channel channel;

    public ServerNode(String name, String ip, int port, Channel channel) {
        this.ip = ip;
        this.port = port;
        this.name = name;
        this.channel = channel;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ServerNode that = (ServerNode) o;
        return port == that.port && ip.equals(that.ip) && name.equals(that.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(ip, port, name);
    }
}
